<?php

/**
 * 前台 舞美工程 模块 Controller
 * ============================================================================
 * TBlog TBlog博客系统　BY Tmac PHP MVC framework
 * $Author: zwt007 $  <zwttmac@qq.com>
 * $Id: news.php 39 2011-07-11 17:12:35Z zwt007 $
 * http://www.t-mac.org；
 */
class wmgcAction extends Action
{

    private $tmp_model;
    private $show_model;
    private $index_model;
    private $difang_model;

    public function _init()
    {
        $this->assign('action', $_GET['TMAC_ACTION']);
        $this->tmp_model = Tmac::model('news');
        $this->show_model = Tmac::model('show');
        $this->index_model = Tmac::model('index');
        $this->difang_model = Tmac::model('difang');


        $username = $this->H($this->getParam('username'));
        $this->userinfo = $this->difang_model->getUserinfo($username);
        $this->config = $this->index_model->getCommon($this->userinfo);

        $nav_array = $this->difang_model->getCategoryArray($this->userinfo['uid'], 0);

        $hotel_list_nopage_array = $this->show_model->getHotelListNoPage($this->userinfo['uid'],5);
        //left hotel nopage
        $news_list_nopage_array = $this->show_model->getArticleNewsListNopage(8, $this->userinfo['uid']);
        //left 会议常识
        $hycs_cid = 70;
        $hycs_list_nopage_array = $this->show_model->getArticleNewsListNopageB($hycs_cid, $this->userinfo['uid']);

        $this->assign('hotel_list_nopage_array', $hotel_list_nopage_array);
        $this->assign('news_list_nopage_array', $news_list_nopage_array);
        $this->assign('hycs_list_nopage_array', $hycs_list_nopage_array);
        $this->assign('hycs_cid', $hycs_cid);
        $this->assign('nav_array', $nav_array);
        $this->assign('userinfo', $this->userinfo);
    }

    public function index()
    {
        $cid = intval($this->getParam('cid'));
        $cid = empty($cid) ? 5 : $cid;
        //取category信息
        $catinfo = $this->show_model->getCategoryInfoById($cid, $this->userinfo['uid']);
        //取文章信息
        $url = PHP_SELF . '?m=wmgc&username=' . $this->userinfo['username'] . '&cid=' . $cid . '&page=';
        global $cat_ids;
        $cat_ids = '';
        $cat_ids = $this->index_model->getSonTreeList($cid, $this->userinfo['uid']);
        $list = $this->tmp_model->getArticleList($url, $cat_ids, $this->userinfo['uid']);

        //下级栏目        
        $url = 'wmgc';        
        $this->index_model->getCategoryList(5, $url, $this->userinfo['uid'], $this->userinfo['username'], $this->config['cfg_indexurl']);

        $this->assign('cid', $cid);
        $this->assign('catinfo', $catinfo);
        $this->assign('list', $list);
        $this->assign('urlfile', $url);
        $this->V('wmgc_list');
    }

    public function show()
    {
        $username = $this->H($this->getParam('username'));
        $userinfo = $this->difang_model->getUserinfo($username);

        $aid = intval($this->getParam('aid'));
        if (empty($aid)) {
            $this->redirect('请选择文章');
            exit();
        }

        //增加一次点击数
        $this->show_model->saveArticleClick($aid);
        $info = $this->tmp_model->getArticleInfo($aid);
        if (!$info) {
            $this->redirect('选择的文章不存在!');
            exit();
        }

        //栏目信息
        $catinfo = $this->show_model->getCategoryInfoById($info['cat_id'], $this->userinfo['uid']);


        $this->assign('info', $info);
        $this->assign('catinfo', $catinfo);

        $this->V('news_show');
    }

    public function page()
    {
        $cat_id = intval($this->getParam('cid'));        
        $cid = empty($cat_id) ? 5 : $cat_id;        
        $catinfo = $this->show_model->getCategoryInfoById($cid, $this->userinfo['uid']);

        //下级栏目
        $url = 'wmgc';        
        $this->index_model->getCategoryList(5, $url, $this->userinfo['uid'], $this->userinfo['username'], $this->config['cfg_indexurl']);

        $this->assign('catinfo', $catinfo);
        $this->assign('cid', $cat_id);
        $this->V('wmgc_page');
    }

}